# Maintainer: Laurent Carlier <Lordheavym@gmail.com>
# Contributor: Allan McRae <mcrae_allan@hotmail.com>
# Contributor: Daniel J Griffiths <griffithsdj@archlinux.us>

pkgname=critter
_origname=CriticalMass
pkgver=1.0.2
pkgrel=12
pkgdesc="Critical Mass (aka Critter) is an SDL/OpenGL space shoot'em up game"
arch=('loong64' 'x86_64')
url="https://sourceforge.net/projects/criticalmass"
license=('GPL')
depends=('sdl_image' 'sdl_mixer' 'libgl')
makedepends=('mesa')
options=(!lto)
source=(https://downloads.sourceforge.net/sourceforge/criticalmass/$_origname-${pkgver}.tar.bz2
        critter-gcc43.patch
        criticalmass-1.0.2-libpng15.patch
        critter.desktop)
md5sums=('e2aff114bffa717fb79c82e1dc473ebe'
         'e936920acce56bfa3b0123ca8b1193a6'
         '76448ba5b7a42aec8fd2a5d1bc31b8e2'
         '98c17809aed964c445adad09827035df')
sha256sums=('846db2d30d39e559612328594084a7aef980169948b2cfaee9fddec8ffdef724'
            'b5eaab0e6eba1d4620ae598c010ca259134a81ef87ee3fce92c3162567491ad7'
            'fcf92674547fa96389d64df2612906a2aac7d82ef19fb01b4665def32a518585'
            '6b429d538537d15a7fa6a2344dbd98a4b9e05b7416c845fef37d0749a915c7c8')

build() {
  cd "${srcdir}"/$_origname-${pkgver}

  patch -Np1 -i ../critter-gcc43.patch
  patch -Np0 -i ../criticalmass-1.0.2-libpng15.patch
  sed -i 's|png12|png16|g' configure.in
  sed -e '/CFLAGS=""/d' -e '/CXXFLAGS=""/d' -i configure.in
  export CXXFLAGS+=' -std=gnu++98'
  ./autogen.sh

  ./configure --prefix=/usr --mandir=/usr/share/man
  make
}

package() {
  cd "${srcdir}"/$_origname-${pkgver}

  make DESTDIR="${pkgdir}" install

  install -Dm644 critter.png "${pkgdir}"/usr/share/pixmaps/critter.png
  install -Dm644 ../critter.desktop \
    "${pkgdir}"/usr/share/applications/critter.desktop
}
